<?

include "../config/constants.php";

if( $_GET[_test] ){
	$_POST[XML] = file_get_contents(TEST_FEED);
	$_POST[CPID] = TEST_CPID;
	$_POST[FEED] = TEST_FEED;
}

$XML = stripslashes($_POST[XML]);
$CPID = $_POST[CPID];
$FEED = $_POST[FEED];

try{
	$req = new HttpRequest(ORCHESTRATOR_URL, HttpRequest::METH_POST);

	$req->addPostFields(array('XML' => $XML));
	$req->addPostFields(array('CPID' => $CPID));
	$req->addPostFields(array('FEED' => $FEED));
	$Body = $req->send()->getBody();

	if( substr( $Body , 0, 5 ) == "ERROR" || substr( $Body, 0, 3 ) == "<br" ){
		echo $Body;
		exit;
	}

	$req = new HttpRequest(INSERT_URL, HttpRequest::METH_POST);
	$req->addPostFields(array('XML' => $Body));
	$req->addPostFields(array('CPID' => $CPID));
	$req->addPostFields(array('FEED' => $FEED));
	
	$Res = $req->send()->getBody();
	echo $Res;

} catch( HttpException $ex ){
	echo $ex;
}

?>

